import axios from '../axios/axios';
import { sm2 } from 'sm-crypto';

/**
 * @param {string} url
 * @param {AxiosRequestConfig} config
 * @returns
 */
const getWithToken = (url, config) => {
	return axios.get(url, {
		...config,
		headers: {
			'Content-Type': 'application/json',
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};
/**
 * @param {string} url
 * @param {Object} data
 * @param {AxiosRequestConfig} config
 * @returns
 */
const putWithToken = (url, data, config) => {
	return axios.put(url, data, {
		...config,
		headers: {
			'Content-Type': 'application/json',
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * @param {string} url
 * @param {Object} data
 * @param {AxiosRequestConfig} config
 * @returns
 */
const postWithToken = (url, data, config) => {
	return axios.post(url, data, {
		...config,
		headers: {
			'Content-Type': 'application/json',
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * token失效，重新刷新链接
 * @param {*} para
 */
export const refreshToken = para => {
	return axios.post(loginUrl + '/ivcs/api/v1/auth/refresh-token', para, {
		headers: {
			'Content-Type': 'application/json'
		}
	});
};

/**
 * 管理员登录
 * @param {*} name
 * @param {*} pwd
 * @param {*} org
 */
export const adminlogin = data => {
	let password = data.password;
	if (publicKey) {
		// const sm2 = require('sm-crypto').sm2;
		const cipherMode = 1; // 1 - C1C3C2，0 - C1C2C3，默认为1
		let encryptData = sm2.doEncrypt(password, publicKey, cipherMode); // 加密结果
		password = encryptData;
	}
	return axios.post(loginUrl + '/ivcs/api/v1/auth/logon', {
		userName: data.name,
		pwd: password,
		org: data.org,
		role: 'admin'
	});
};

/**
 * 获取不同状态的坐席数量
 */
export const getagentcount = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/agents/count/status');
};

/**
 * 获取坐席列表
 * @param {*} page
 * @param {*} pageSize
 * @param {*} status
 * @param {*} keyWord
 * @param {*} startTime
 * @param {*} endTime
 */
export const getagentlist = data => {
	return axios.get(
		loginUrl +
			'/ivcs/api/v1/agents/list?page=' +
			data.page +
			'&pageSize=' +
			data.pageSize +
			'&status=' +
			data.status +
			'&checkIn=' +
			data.checkIn +
			'&keyWord=' +
			data.keyWord +
			'&startTime=' +
			data.startTime +
			'&endTime=' +
			data.endTime,
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 删除坐席（下线）
 * @param {*} agentId
 */
export const deleteagent = agentId => {
	return axios.delete(loginUrl + '/ivcs/api/v1/agents/' + agentId);
};

/**
 * 获取用户列表
 * @param {*} page
 * @param {*} pagesize
 * @param {*} role  用户角色
 * @param {*} token  用户token
 */
export const getUserList = data => {
	return axios.get(loginUrl + '/ivcs/api/v1/auth/users' + '?page=' + data.page + '&pageSize=' + data.pageSize + '&role=' + data.role);
};

/**
 * 删除用户
 * @param {*} userId
 */
export const deleteAccount = userId => {
	return axios.delete(loginUrl + '/ivcs/api/v1/auth/users/' + userId);
};

/**
 * 更新用户信息
 * @param {*} userId
 * @param {*} params
 * @param {*} token
 */
export const updateAccountInfo = data => {
	let params = data.params;
	if (params.length > 0) {
		params.forEach(item => {
			if (item.op === 'replace' && item.path === '/pwd') {
				let password = item.value;
				if (publicKey) {
					// const sm2 = require('sm-crypto').sm2;
					const cipherMode = 1; // 1 - C1C3C2，0 - C1C2C3，默认为1
					let encryptData = sm2.doEncrypt(password, publicKey, cipherMode); // 加密结果
					password = encryptData;
				}
				item.value = password;
			}
		});
	}
	return axios.patch(loginUrl + '/ivcs/api/v1/auth/users/' + data.userId, params, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`),
			'Content-Type': 'application/json'
		}
	});
};

/**
 * 超级管理更新用户信息
 * @param {*} userId
 * @param {*} params
 * @param {*} token
 */
export const adminUpdateAccountInfo = data => {
	let params = data.params;
	if (params.length > 0) {
		params.forEach(item => {
			if (item.op === 'replace' && item.path === '/pwd') {
				let password = item.value;
				if (publicKey) {
					// const sm2 = require('sm-crypto').sm2;
					const cipherMode = 1; // 1 - C1C3C2，0 - C1C2C3，默认为1
					let encryptData = sm2.doEncrypt(password, publicKey, cipherMode); // 加密结果
					password = encryptData;
				}
				item.value = password;
			}
		});
	}
	return axios.patch(loginUrl + '/ivcs/api/v1/auth/users/' + data.userId, params, {
		headers: {
			'x-access-token': localStorage.getItem('superAdminToken'),
			'Content-Type': 'application/json'
		}
	});
};

/**
 * 获取管理员列表
 * @param {*} page
 * @param {*} pagesize
 */
export const getAdminUserList = data => {
	console.log(axios.defaults.headers);
	return axios.get(loginUrl + '/ivcs/api/v1/auth/users' + '?page=' + data.page + '&pageSize=' + data.pageSize + '&role=admin', {
		headers: {
			'x-access-token': localStorage.getItem('superAdminToken'),
			'Content-Type': 'application/json'
		}
	});
};

/**
 * 获取当前机构下所有分组
 */
export const getAllGroups = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/groups/select/options', {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 根据用户id获取绑定的分组
 * @param {*} userId
 * @param {*} page
 * @param {*} pagesize
 */
export const getGroupWithUserId = data => {
	return axios.get(loginUrl + '/ivcs/api/v1/user-group-relations' + '?page=' + data.page + '&pageSize=' + data.pageSize + '&userId=' + data.userId, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 给坐席添加分组
 * @param {*} userId  坐席用户id
 * @param {*} groupId  分组id
 * @param {*} weight  权重
 * @param {*} isChief 是否组长
 */
export const addGroupsWithAgent = data => {
	return axios.post(
		loginUrl + '/ivcs/api/v1/user-group-relations',
		{
			userId: data.userId,
			groupId: data.groupId,
			weight: data.weight,
			isChief: data.isChief
		},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 删除坐席绑定的分组
 * @param {*} id
 */
export const deleteGroupsWithAgent = id => {
	return axios.delete(loginUrl + '/ivcs/api/v1/user-group-relations/' + id);
};

/**
 * 编辑座席分组
 * @param {*} userId  坐席用户id
 * @param {*} groupId  分组id
 * @param {*} weight  权重
 * @param {*} isChief 是否组长
 * @param {*} checkId 当前修 _id
 */
export const modifyGroupsWithAgent = data => {
	return axios.put(
		loginUrl + '/ivcs/api/v1/user-group-relations/' + data.checkId,
		{
			userId: data.userId,
			groupId: data.groupId,
			weight: data.weight,
			isChief: data.isChief
		},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 账号注册
 * @param {*} name 用户名
 * @param {*} pwd  密码
 * @param {*} org  所属机构
 * @param {*} role  角色
 * @param {*} customerLevel  用户等级
 * @param {*} isRobot  是否是机器人坐席
 * @param {*} profile  用户附加信息
 * @param {*} token  当前用户的token
 */
export const accountRegister = data => {
	if (data.role !== 'agent') {
		data.isRobot = false;
	}
	let password = data.pwd;
	if (publicKey) {
		// const sm2 = require('sm-crypto').sm2;
		const cipherMode = 1; // 1 - C1C3C2，0 - C1C2C3，默认为1
		let encryptData = sm2.doEncrypt(password, publicKey, cipherMode); // 加密结果
		password = encryptData;
	}
	let userItem = { userName: data.name, pwd: password, role: data.role, org: data.org, isRobot: data.isRobot, profile: data.profile };
	if (data.customerLevel) {
		userItem.customerLevel = data.customerLevel;
	}
	return axios.post(loginUrl + '/ivcs/api/v1/auth/register', userItem);
};

/**
 * 修改用户账号信息
 * @param {*} name 用户名
 * @param {*} customerLevel  用户等级
 * @param {*} profile  用户附加信息
 * @param {*} token  当前用户的token
 */
export const updateRegister = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/auth/users/${data.userId}`, data);
};

/**
 * 获取所有用户的额外属性key
 */
export const getAttributeKeys = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/auth/schedulingAttributes/keys', {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取所有用户额外属性对应的存储值，主要用于坐席派工规则
 * @param {*} key
 */
export const getAttributeValues = key => {
	return axios.get(loginUrl + '/ivcs/api/v1/auth/schedulingAttributes/values?key=' + key, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取分组列表
 * @param {*} page
 * @param {*} pagesize
 */
export const getGroupsList = data => {
	return axios.get(loginUrl + '/ivcs/api/v1/groups' + '?page=' + data.page + '&pageSize=' + data.pageSize, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 新增分组
 * @param {*} data
 */
export const addGroups = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/groups', data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 删除分组
 * @param {*} id
 */
export const deleteGroups = data => {
	return axios.delete(loginUrl + '/ivcs/api/v1/groups/' + data.id);
};

/**
 * 修改分组名
 * @param {*} id  分组id
 * @param {*} name 名称
 */
export const updateGroups = data => {
	return axios.put(
		loginUrl + '/ivcs/api/v1/groups/' + data.id,
		{
			name: data.name
		},
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 更新分组的派工规则
 * @param {*} id
 * @param {*} policyData
 */
export const updatePolicy = data => {
	return axios.put(
		loginUrl + '/ivcs/api/v1/groups/' + data.id,
		{
			customizedPolicy: data.customizedPolicy,
			defaultPolicy: data.defaultPolicy,
			name: data.name
		},
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 获取表单列表
 * @param {*} page
 * @param {*} pagesize
 */
export const getFormTemplateList = data => {
	console.log(data);
	return axios.get(loginUrl + '/ivcs/api/v1/formTemplates' + '?page=' + data.page + '&pageSize=' + data.pageSize + '&isEmpty=' + data.isEmpty, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取业务列表
 * @param {*} page
 * @param {*} pageSize
 * @param {*} name
 */
export const getBusinessList = data => {
	return axios.get(loginUrl + '/ivcs/api/v1/businessflow' + '?page=' + data.page + '&pageSize=' + data.pageSize + '&name=' + data.name);
};

/**
 * 给分组绑定表单
 * @param {*} groupsId
 * @param {*} value
 */
export const bindFormTemplateWithGroups = data => {
	return axios.patch(
		loginUrl + '/ivcs/api/v1/groups/' + data.groupId,
		[
			{
				op: 'replace',
				path: 'formTemplates',
				value: data.value
			}
		],
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 给分组绑定业务流程
 * @param {*} groupsId
 * @param {*} businessFlowId
 */
export const bindBusinessFlowWithGroups = data => {
	return axios.patch(
		loginUrl + '/ivcs/api/v1/groups/' + data.groupId,
		[
			{
				op: 'replace',
				path: '/businessFlowId',
				value: data.businessFlowId
			}
		],
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 给分组绑定业务流程
 * @param {*} groupsId
 * @param {*} value 工作流数据
 */
export const bindWorkFlowWithGroups = data => {
	return axios.patch(
		loginUrl + '/ivcs/api/v1/groups/' + data.groupId,
		[
			{
				op: 'replace',
				path: 'workflowSteps',
				value: data.value
			}
		],
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 创建表单模版
 * @param {*} name  表单名
 * @param {*} fields  表单选项
 */
export const createFormTemplate = data => {
	return axios.post(
		loginUrl + '/ivcs/api/v1/formTemplates',
		{
			name: data.name,
			fields: data.fields
		},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 根据id删除表单
 * @param {*} id
 */
export const deleteFormTemplateWithId = id => {
	return axios.delete(loginUrl + '/ivcs/api/v1/formTemplates/' + id);
};

/**
 * 根据表单id更新表单内容
 * @param {*} id
 * @param {*} name
 * @param {*} fields
 */
export const updateFormTemplate = data => {
	return axios.put(
		loginUrl + '/ivcs/api/v1/formTemplates/' + data.id,
		{
			name: data.name,
			fields: data.fields
		},
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 获取当前机构下工作流步骤的列表
 * @param page
 * @param pagesize
 * @returns {AxiosPromise<any>}
 */
export const getWorkflowStepList = data => {
	return axios.get(loginUrl + '/ivcs/api/v1/humanFlow' + '?page=' + data.page + '&pageSize=' + data.pageSize, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取某一个人的人工工作流
 * @param {int} id
 * @returns
 */
export const getHumanflowById = id => {
	return axios.get(loginUrl + '/ivcs/api/v1/humanFlow/' + id);
};

/**
 * 创建工作流步骤
 * @param name
 * @param fields
 * @returns {AxiosPromise<any>}
 */
export const createWorkflowStep = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/humanFlow', data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 删除工作流步骤根据id
 * @param id
 * @returns {AxiosPromise}
 */
export const deleteWorkflowStepWithId = id => {
	return axios.delete(loginUrl + '/ivcs/api/v1/humanFlow/' + id);
};

/**
 * 更新工作流步骤
 * @param id 工作流ID
 * @param data 需要更新的工作流
 * @returns {AxiosPromise<any>}
 */
export const updateWorkflowStep = (data, id) => {
	return axios.put(loginUrl + '/ivcs/api/v1/humanFlow/' + id, data);
};

/**
 * 删除业务
 * @param {*} id
 */
export const deleteBusiness = id => {
	return axios.delete(loginUrl + '/ivcs/api/v1/businessflow/' + id);
};

/**
 * 创建业务
 * @param {*} data.name 业务名
 * @param {*} data.limit 最大呼叫
 */
export const createBusiness = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/businessflow', data);
};

/**
 * 获取房间token
 * @param {*} roomid
 * @param {*} userName
 */
export const getRoomToken = (roomid, userName) => {
	return axios.post(
		loginUrl + '/ivcs/api/v1/tokens',
		{
			room: roomid,
			user: userName ? userName : 'admin',
			role: 'presenter',
			domain: DOMAIN
		},
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 获取所有通话中数据
 * @param page  当前页
 * @param pageSize 每页多少条数据
 * @param startCallTime 接通时间
 * @param startDialingTime 通话时长
 * @param agentId 座席 name
 * @param groupId 组 id
 * @param isRobot 是否机器人
 * @param sessionId 会话 id
 */

export const getSessionsList = data => {
	console.log(data);
	return axios.get(
		loginUrl +
			`/ivcs/api/v1/sessions/list-ongoing?page=${data.page}&pageSize=${data.pageSize}&startCallTime=${data.startCallTime}&startDialingTime=${data.startDialingTime}&agentId=${data.agentId}&groupId=${data.groupId}&isRobot=${data.isRobot}&sessionId=${data.sessionId}`,
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 获取业务的话术流程
 * @param {*} businessId
 */
export const getBusinessWorkflow = businessId => {
	return axios.get(loginUrl + '/ivcs/api/v1/businessflow/' + businessId, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 给业务绑定话术
 * @param {*} workflow
 * @param {*} businessId
 */
export const bindWorkFlowWithBusinessId = (workflow, businessId, status = false) => {
	return axios.patch(
		loginUrl + '/ivcs/api/v1/businessflow/' + businessId,
		[
			{
				op: 'replace',
				path: '/workflow',
				value: workflow
			},
			{
				op: 'update',
				path: '/status',
				value: status
			}
		],
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 超级管理员登录
 * @param {*} name
 * @param {*} pwd
 */
export const superlogin = (name, pwd) => {
	let password = pwd;
	if (publicKey) {
		// const sm2 = require('sm-crypto').sm2;
		const cipherMode = 1; // 1 - C1C3C2，0 - C1C2C3，默认为1
		let encryptData = sm2.doEncrypt(pwd, publicKey, cipherMode); // 加密结果
		password = encryptData;
	}
	return axios.post(
		loginUrl + '/ivcs/api/v1/auth/logon',
		{
			userName: name,
			pwd: password,
			role: 'super-admin'
		},
		{
			'Content-Type': 'application/json'
		}
	);
};

/**
 * 管理员账号注册
 * @param {*} name 用户名
 * @param {*} pwd  密码
 * @param {*} org  所属机构
 * @param {*} role  角色
 * @param {*} customerLevel  用户等级
 * @param {*} isRobot  是否是机器人坐席
 * @param {*} profile  用户附加信息
 * @param {*} token  当前用户的token
 */
export const superAccountRegister = data => {
	if (data.role !== 'agent') {
		data.isRobot = false;
	}
	let password = data.pwd;
	if (publicKey) {
		// const sm2 = require('sm-crypto').sm2;
		const cipherMode = 1; // 1 - C1C3C2，0 - C1C2C3，默认为1
		let encryptData = sm2.doEncrypt(password, publicKey, cipherMode); // 加密结果
		password = encryptData;
	}
	let userItem = { userName: data.name, pwd: password, role: data.role, org: data.org, isRobot: data.isRobot, profile: data.profile };
	if (data.customerLevel) {
		userItem.customerLevel = data.customerLevel;
	}
	return axios.post(loginUrl + '/ivcs/api/v1/auth/register', userItem, {
		headers: {
			'Content-Type': 'application/json',
			'x-access-token': data.token
		}
	});
};

/**
 * 获取用户列表
 * @param {*} page
 * @param {*} pagesize
 * @param {*} role  用户角色
 * @param {*} token  用户token
 */
export const superUserList = data => {
	console.log(data);
	return axios.get(loginUrl + '/ivcs/api/v1/auth/users' + '?page=' + data.page + '&pageSize=' + data.pageSize + '&role=' + data.role, {
		headers: {
			'Content-Type': 'application/json',
			'x-access-token': localStorage.getItem('superAdminToken')
		}
	});
};

/**
 *  获取会话详情
 * @param {*} sessionId
 * @param {*} key
 */
export const getsessiondetail = (sessionId, key) => {
	return axios.get(loginUrl + '/ivcs/api/v1/sessions/' + sessionId + '/record?key=' + key);
};

/**
 * 获取用户提交的表单信息
 * @param {*} formid
 */
export const getuserforminfo = formid => {
	return axios.get(loginUrl + '/ivcs/api/v1/formInfo/' + formid);
};

/**
 * 删除录像文件
 * @param {*} recordid
 */
export const deletevideofile = recordid => {
	return axios.delete(loginUrl + '/ivcs/api/v1/recording/' + recordid);
};

/**
 * 获取房间中所有的流
 * @param {*} roomId
 */
export const getroomallstreamlist = roomId => {
	return axios.get(loginUrl + '/ivcs/api/v1/rooms/' + roomId + '/streams', {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取房间中某一个具体流的详细信息
 * @param {*} roomId
 * @param {*} streamId
 */
export const getspecifiedstreaminfo = (roomId, streamId) => {
	return axios.get(loginUrl + '/ivcs/api/v1/rooms/' + roomId + '/streams/' + streamId, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取会话业务流程清单的信息
 * @param sessionId
 * @returns {AxiosPromise<any>}
 */
export const getSessionCheckListInfo = sessionId => {
	return axios.get(loginUrl + '/ivcs/api/v1/sessions/' + sessionId + '/checkList');
};

/**
 *  获取会话过程中的坐席采集的用户信息
 * @param {*} sessionId
 */
export const getsessionformdata = sessionId => {
	return axios.get(loginUrl + '/ivcs/api/v1/sessions/' + sessionId + '/applications');
};

/**
 * 强拆会话
 * @param {*} sessionId
 */
export const dropsession = sessionId => {
	return axios.delete(loginUrl + '/ivcs/api/v1/sessions/' + sessionId);
};

/**
 * 设置工作时间
 *  @param {*} startTime
 *  @param {*} endTime
 */

export const setWorkTime = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/work-time', data);
};

/**
 * 查询工作时间
 */

export const getWorkTime = data => {
	return axios.get(loginUrl + '/ivcs/api/v1/work-time/' + data.groupId);
};

/**
 * 更新工作时间
 * @param {Number}  id 工作时间id
 */

export const updateWorkTime = data => {
	return axios.put(loginUrl + '/ivcs/api/v1/work-time/' + data.id, data);
};

/**
 * 查询工作流表格
 * @param {String} sessionId
 * @returns
 */
export const getWorkflowSteps = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/humanFlow/detail/sessionid/${sessionId}`);
};

/**
 * 保存技能分组
 * @param { Object } data 技能分组数据
 * @param { Number } userId 用户 ID
 * @returns
 */
export const saveGroupPriority = (data, userId) => {
	return axios.post(loginUrl + `/ivcs/api/v1/user-group-relations/users/${userId}/groups`, data);
};

/**
 * 获取智能问答数据
 * @param {Number} businessFlowId
 * @param {Number} page
 * @param {Number} pageSize
 * @param { String } filterEmpty 是否排除空
 */
export const getAiQuestion = (businessFlowId, page, pageSize, filterEmpty) => {
	return axios.get(loginUrl + `/ivcs/api/v1/businessflow/${businessFlowId}/intelligentReply?page=${page}&pageSize=${pageSize}&filterEmptyReply=${filterEmpty}`);
};

/**
 * 保存智能问答数据
 * @param {Number} businessFlowId
 */
export const saveAiQuestion = (businessFlowId, data) => {
	return axios.post(loginUrl + `/ivcs/api/v1/businessflow/${businessFlowId}/intelligentReply`, data);
};

/**
 *
 * @param {String} libType 语料库类型
 * @param {String} point 意图点
 * @returns
 */
export const getDownloadNul = (libType, point) => {
	return axios.get(loginUrl + `/ivcs/znlu/api/v1/intent_libs/${libType}/intents_for_testlangfile/${point}`);
};

/**
 * 从意图库里面，获取意图点
 * @param {String} intentLibName
 * @param {Number} page
 * @param {Number} pageSize
 * @returns
 */
export const getIntentDotList = (intentLibName, page, pageSize) => {
	return axios.get(loginUrl + `/ivcs/api/v1/intent/libs/${intentLibName}/intentPoints?page=${page}&pageSize=${pageSize}`);
};

/**
 * 获取意图库列表
 * @param {String} value
 * @param {Number} page
 * @param {Number} pageSize
 * @returns
 */
export const getIntentLibaryList = (value, page, pageSize) => {
	return axios.get(loginUrl + `/ivcs/api/v1/intent/libs?type=${value}&page=${page}&pageSize=${pageSize}`);
};

/**
 *获取工作日列表
 * @param {Number} page 页码
 * @param {Number} pageSize 条数
 * @param {String} name 规则名称
 * @param {String} startTime 创建时间段
 * @param {String} endTime 	结束时间段
 * @param {Number} username 创建人姓名
 */
export const getWorkingDaysList = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/work-day?page=${data.page}&pageSize=${data.pageSize}&name=${data.name}&startTime=${data.startTime}&endTime=${data.endTime}&username=${data.username}`);
};

/**
 *新增工作日规则
 * @param {String} name 规则名称
 * @param {Array} dates 休息日日期数字，日期格式 YYYY-MM-DD
 */
export const setWorkingDays = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/work-day', data);
};

/**
 * 查看工作日规则
 * @param {Number} id 规则id
 */
export const getWorkingDates = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/work-day/${id}`);
};

/**
 * 修改工作日规则
 * @param {Number} id 规则id
 * @param {Object} data data(name,dates) name为规则名称，dates为修改的工作日
 * @returns  Proimse <Object,error>
 */
export const modifyWorkingDays = (id, data) => {
	return axios.put(loginUrl + `/ivcs/api/v1/work-day/${id}`, data);
};

/**
 * 获取工作时间规则列表
 * @param {Object} data {page:页码, pageSize:条数,name:规则名称,startTime:开始时间段,endTime:结束时间,username:创建人姓名}
 * @returns Proimse <Object,error>
 */
export const getWorkingTimeList = data => {
	return axios.get(
		loginUrl +
			`/ivcs/api/v1/work-time/?page=${data.page}&pageSize=${data.pageSize}&name=${data.name}
	&startTime=${data.startTime}&endTime=${data.endTime}&username=${data.username}`,
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 创建工作时间规则
 * @param {Object} data  创建工作时间规则的数据
 * @returns  Proimse <Object,error>
 */
export const createWorkingTime = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/work-time/', data);
};

/**
 * 修改工作时间规则
 * @param {Object} data   修改工作时间规则的数据
 * @returns Proimse <Object,error>
 */
export const updateWorkingTime = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/work-time/${data.id}`, data);
};

/**
 * 查看工作时间详情
 * @param {Number} WorkingTimeId 某一条工作时间Id
 * @returns Proimse <Number,error>
 */
export const selectWorkingTimeByList = WorkingTimeId => {
	return axios.get(loginUrl + `/ivcs/api/v1/work-time/${WorkingTimeId}`);
};

/**
 * 绑定工作时间
 * @param {Object} data {id:分组id,workTimes:绑定的工作时间数据}
 * @returns Proimse <Object,error>
 */
export const bindGroupWorkingTime = data => {
	return axios.patch(loginUrl + `/ivcs/api/v1/groups/${data.id}/workTime`, data.workTimes);
};

/**
 * 获取业务场景列表
 * @param {Object} data {page:页码, pageSize:条数,name:业务场景名称,startTime:开始时间段,endTime:结束时间,creator:创建名称}
 * @returns Proimse <Object,error>
 */

export const getBusinessScenceList = data => {
	return axios.get(
		loginUrl +
			`/ivcs/api/v1/bizscenarios/list?page=${data.page}&pageSize=${data.pageSize}&name=${data.name}
			&startTime=${data.startTime}&endTime=${data.endTime}&creator=${data.creator}`,
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 创建业务场景
 * @param {Object} data 创建业务场景数据
 * @returns Proimse <Object,error>
 */
export const createBusinessScence = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/bizscenarios/', data);
};

/**
 *修改业务场景
 * @param {Number} scenarioId 业务场景ID
 * @returns Proimse <Number,error>
 */
export const updateBusinessScence = (scenarioId, name) => {
	return axios.put(
		loginUrl + `/ivcs/api/v1/bizscenarios/${scenarioId}`,
		{ name },
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 *启用或者停用业务场景
 * @param  {Object} data {scenarioId:业务场景ID}
 * @returns Proimse <Object,error>
 */
export const startBusinessScence = data => {
	return axios.put(
		loginUrl + `/ivcs/api/v1/bizscenarios/${data.id}/state`,
		{ enable: data.state },
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 获取业务场景详情
 * @param { Number } id 业务场景 ID
 * @returns
 */
export const getBizscenariosInfo = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${id}`);
};

/**
 * 获取技能组列表
 * @param {{scenarioId: number | string, page: number | string, pageSize: number | string}} data
 * @returns
 */
export const getGroupsDetails = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/groups/details/agents?scenarioId=${data.scenarioId}&page=${data.page}&pageSize=${data.pageSize}`);
};

/**
 * 设置业务场景配置项
 * @param { Number } id 场景ID
 * @param { String } profileType 要设置的类型： aiBizflow - AI工作流 humanBizflow - 人工工作流 schedPolicy - 派工规则 form - 表单 agentGroup - 技能组  videoRecord - 视频录制
 * @param { Number | Array | Object } 设定的值
 * @returns
 */
export const setBizscenariosProfile = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${data.id}/profiles/${data.profileType}`, data.value);
};

/**
 * 同步外系统工作日
 * @param { String } year 需要同步哪年的工作日
 */
export const syncWorkingDays = year => {
	return axios.get(loginUrl + `/ivcs/api/v1/work-day/import/url?year=${year}`);
};

/**
 * 根据Session获取表单列表
 * @param {Number} page 页面号
 * @param {Number} pageSize 页面数
 * @param {String} sessionId 会话Id
 * @param {String} followId 表单流水号
 * @param {String} toClientId 接收端Id
 * @param {String} agentName 坐席名称
 * @param {Date} pushStartTime 推送开始时间
 * @param {Date} pushEndTime 推送结束时间
 * @param {Date} submitStartTime 提交开始时间
 * @param {Date} submitEndTime 提交结束时间
 * @param {String} name 表单名称
 * @param {String} status 表单状态
 */
export const getFormDataList = data => {
	return axios.get(
		loginUrl +
			`/ivcs/api/v1/formHistory/list?page=${data.page}&pageSize=${data.pageSize}&sessionId=${data.sessionId}&followId=${data.followId}&toClientId=${data.toClientId}&agentName=${data.agentName}&pushStartTime=${data.pushStartTime}&pushEndTime=${data.pushEndTime}&formName=${data.name}&status=${data.status}`
	);
};

/**
 *
 * @param { Number } id 表单记录 ID
 * @returns
 */
export const getFormDetail = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/formHistory/${id}`);
};
/**
 *
 * @param { Number } id 业务场景表单 ID
 * @returns
 */
export const getSceneFormDetail = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/formTemplates/${id}/detail`);
};
/**
 * 获取所有表单名称
 * @returns
 */
export const getAllFormName = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/formTemplates/all');
};

/**
 * 业务绑定表单列表
 * @param  {Number} {sceneId:业务场景ID}
 * @returns Proimse <Object,error>

 */
export const getBizscenariosBindForm = sceneId => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${sceneId}/forms`);
};

/**
 * Ai 保存工作流校验 Form 表单
 * @param { Number } id AI工作流 id
 * @param { Array } formIds 绑定 form 表单数组
 */

export const updateFormDataByAiFlow = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/businessflow/${data.id}/forms`, data);
};

/**
 * 场景转接模板,获取业务场景列表不分页
 */
export const getAllBusinessScenceList = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/bizscenarios/select/options');
};

/**
 * 系统设置列表数据
 */
export const getConfigList = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/systemconfig/list');
};

/**
 * 设置配置项状态
 * @param {Number} id 需要更新的配置项ID
 * @param {boolean} status 启用或者停用配置项：true - 启用；false - 停 用
 */
export const setConfigStatus = (id, status) => {
	return axios.put(loginUrl + `/ivcs/api/v1/systemconfig/${id}/status`, status);
};

/**
 * 更新配置项
 * @param {Number} id 需要更新的配置项ID
 * @param {Object} value 设置配置项的数据
 */
export const updateConfig = (id, value) => {
	return axios.put(loginUrl + `/ivcs/api/v1/systemconfig/${id}/value`, value);
};

/**
 * 获取转接记录列表
 * @param  {Number} {sessionId: 会话SessionID}
 * @returns Proimse <Object,error>

 */
export const getTransferRecord = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/transfer/history`);
};

/**
 * Ai 保存工作流校验 业务场景
 * @param { Number } id AI工作流 id
 * @param { Array } scenIds 业务场景数组
 */

export const updateScenIdsByFlow = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/businessflow/${data.id}/scens`, data);
};

/**
 * 获取聊天历史记录
 * @param { Number } sessionId  会话Id
 */
export const getSessionMessage = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/im/messages`);
};

/**
 * 下载聊天历史记录
 * @param { Number } sessionId  会话Id
 */
export const downloadSessionMessage = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/im/messages/download`, {
		responseType: 'blob'
	});
};

/**
 * 获取全局校验配置表格记录
 * @param { Number } sessionId  会话Id
 */
export const getSessionValidateTable = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/validations/agents`);
};
/**
 * 获取全局校验消息记录
 * @param { Number } sessionId  会话Id
 */
export const getSessionMessageRecord = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/validations/details`);
};

/**
 *获取用户在会话中的聊天文件和业务操作文件列表
 * @param { Number } sessionId  会话Id
 * @param { String } type  文件类型   im是聊天文件，operations是业务操作文件
 */
export const getSessionFileList = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${data.sessionId}/${data.type}/files?page=${data.page}&pageSize=${data.pageSize}`);
};
/**
 * 获取用户在会话中提交的个人信息
 * @param { Number } sessionId  会话Id
 */
export const getUserMessage = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/formInfo`);
};
/**
 * 获取用户在会话中坐席发起的录像文件
 * @param { Number } sessionId  会话Id
 */
export const getRecordingVideos = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/recording/videos`);
};
/**
 * 获取用户在会话中产生的接听记录
 * @param { Number } sessionId  会话Id
 */
export const getTransferList = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${data.sessionId}/invitations?page=${data.page}&pageSize=${data.pageSize}`);
};
/**
 * 获取用户在会话中产生的接听记录里面的工作流工作详情
 * @param { Number } sessionId  会话Id
 */
export const getWorkflowCompletedDetail = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${data.sessionId}/invitations/${data.invitationId}/workflows`);
};

/**
 *获取用户在会话中的聊天文件和业务操作文件列表按文件名搜索
 * @param { Number } sessionId  会话Id
 * @param { String } type  文件类型   im是聊天文件，operations是业务操作文件, query 文件名
 */
export const getSelectSessionFileListByName = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${data.sessionId}/${data.type}/files?query=${data.query}&page=${data.page}&pageSize=${data.pageSize}`);
};

/**
 * 上传文件
 * @param {*} data
 */
export const uploadFileWithFormData = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/upload', data, {
		headers: {
			'Content-Type': 'multipart/form-data'
		},
		timeout: uploadFileTimeout // Timeout in milliseconds (5 seconds in this case)
	});
};

/**
 * 上传文件的配置信息，供 el-upload 使用
 */
export const getUploadFileConfig = () => {
	return {
		url: loginUrl + '/ivcs/api/v1/upload',
		headers: {
			// 使用 el-upload 时，会自动添加 'Content-Type': 'multipart/form-data', 重复添加会导致 Error: Multipart: Boundary not found 错误
			// 'Content-Type': 'multipart/form-data',
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		},
		timeout: uploadFileTimeout // Timeout in milliseconds (5 seconds in this case)
	};
};

/**
 * 获取NLP模板返回的结果值
 */
export const getThirdNlpList = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/businessflow/thirdnlp/intents');
};

// 获取AI流程下的视频列表
export const getAiworkFlowVideoList = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/businessflow/${data.bizflowId}/videos?type=${data.type}&page=${data.page}&pageSize=${data.pageSize}`);
};
//上传一个视频
export const uploadVideoByAiworkId = (bizflowId, data) => {
	return axios.post(loginUrl + `/ivcs/api/v1/businessflow/${bizflowId}/videos`, data);
};
// 更新视频信息
export const updateVideoMessage = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/businessflow/${data.bizflowId}/videos/${data.videoId}`, { description: data.description });
};
// 删除指定的视频
export const deleteVideoById = data => {
	return axios.delete(loginUrl + `/ivcs/api/v1/businessflow/${data.bizflowId}/videos/${data.videoId}`);
};

/**
 * 业务场景配置项, 启用/停用  人工通话ASR（语音转文字）
 * @param { Number } scenarioId 场景ID
 * @param { Boolean } enable  = true || false
 */
export const setEnableAsr = (scenarioId, enable) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${scenarioId}/isHumanAsrOn`, enable);
};
/**
 * 业务场景配置项设置,字幕配置类型
 * @param { Number } scenarioId 场景ID
 * @param { object } drawTextOptions ={ agent :坐席显示字幕 ,customer: 访客字幕,recording : 录像文件字幕}
 */
export const setDrawTextOptions = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenarioId}/drawTextOptions`, data);
};

// 选择补录节点
export const updateRerecordingNode = data => {
	return axios.post(
		loginUrl + '/ivcs/api/v1/processRecord/updateNeedRerecord',
		{
			ids: data.ids,
			bizrecordId: data.bizrecordId,
			updatedAt: data.updatedAt,
			needRerecord: true
		},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

//获取证言列表
export const getTestimonyList = bizscenarioId => {
	return axios.get(loginUrl + `/ivcs/api/v1/testimony/list?bizscenarioId=${bizscenarioId}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

//创建证言
export const addTestimony = (bizscenarioId, message) => {
	return axios.post(
		loginUrl + '/ivcs/api/v1/testimony',
		{
			bizscenarioId: bizscenarioId,
			message: message
		},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

//更新证言
export const updateTestimony = (message, id) => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/testimony/${id}/update`,
		{
			message: message
		},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

//删除证言
export const deleteTestimony = id => {
	return axios.delete(loginUrl + `/ivcs/api/v1/testimony/${id}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};
/**
 * 绑定证言
 * @param {Number} id //工作流ID
 * @returns
 */
export const bindTestimony = data => {
	return axios.put(
		loginUrl +
			`/ivcs/api/v1/bizscenarios/${data.id}/testimony
		`,
		{ testimonyIds: data.testimonyIds },
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};
/**
 * 业务场景配置项, 设置人工坐席TTS辅助播报 启用/停用
 * @param { Number } scenarioId 场景ID
 * @param { Boolean } enable  = true || false
 */
export const setAgentTtsOption = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenarioId}/agentTtsOption`, data);
};

/**
 * 业务场景配置项, 设置当前业务场景是否开启双录功能
 * @param { Number | String } scenarioId 场景ID
 * @param { Boolean } enable true: 开启双录，false: 关闭双录
 */
export const setSystemRecordOn = (scenarioId, enable) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${scenarioId}/isSystemRecordOn`, { enable });
};

/**
 * 根据业务场景 ID 获取 TTS 播报条目
 * @param { Number | String } sceneId 业务场景 id
 * @param { { page: Number | String, pageSize: Number | String } }  page
 * @param pageSize
 * @returns
 */
export const getTTSItemsBySceneId = (sceneId, { page, pageSize }) => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${sceneId}/ttsspeech?page=${page}&pageSize=${pageSize}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 根据业务场景 ID 创建 TTS 播报条目
 * @param { Number | String } sceneId 业务场景 id
 * @param { { title: String, content: String } }  title
 * @param content
 * @returns
 */
export const addTTSItemBySceneId = (sceneId, { title, content }) => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/bizscenarios/${sceneId}/ttsspeech`,
		{ title, content },
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 修改 TTS 播报条目
 * @param { Number | String } sceneId 业务场景 id
 * @param { Number | String } ttsId tts 条目的 id
 * @param { { title: String, content: String } }  title
 * @param content
 * @returns
 */
export const updateTTSItem = (sceneId, ttsId, { title, content }) => {
	return axios.put(
		loginUrl + `/ivcs/api/v1/bizscenarios/${sceneId}/ttsspeech/${ttsId}`,
		{ title, content },
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 删除 TTS 播报条目
 * @param { Number | String } sceneId 业务场景 id
 * @param { Number | String } ttsId tts 条目的 id
 * @returns
 */
export const deleteTTSItem = (sceneId, ttsId) => {
	return axios.delete(loginUrl + `/ivcs/api/v1/bizscenarios/${sceneId}/ttsspeech/${ttsId}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取坐席信息
 * @param {*} agentId  坐席ID
 */
export const getAgentInfo = agentId => {
	// /ivcs/api/v1/auth/users/names/:userName/roles/:role
	return axios.get(loginUrl + `/ivcs/api/v1/auth/users/names/${agentId}/roles/agent`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取业务场名字详情
 * @param { Number } bizScenarioId 场景ID
 */
export const getBusinessScenceName = bizScenarioId => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${bizScenarioId}/details`);
};

/**
 * 业务记录列表
 * @param {*} data {page, pageSize, businessflowId, startTime, endTime, bizScenarioName, status, id, sessionId, customerName, agentName}
 * @returns
 */
export const getBizrecordList = data => {
	let param = '?page=' + data.page + '&pageSize=' + data.pageSize;
	if (data.businessflowId) {
		param += '&businessflowId=' + data.businessflowId;
	}
	if (data.startTime) {
		param += '&startTime=' + data.startTime;
	}
	if (data.endTime) {
		param += '&endTime=' + data.endTime;
	}
	if (data.bizScenarioName) {
		param += '&bizScenarioName=' + data.bizScenarioName;
	}
	if (parseInt(data.status, 10) >= 0) {
		param += '&status=' + data.status;
	}
	if (data.id) {
		param += '&id=' + data.id;
	}
	if (data.sessionId) {
		param += '&sessionId=' + data.sessionId;
	}
	if (data.customerName) {
		param += '&customerName=' + data.customerName;
	}
	if (data.agentName) {
		param += '&agentName=' + data.agentName;
	}
	if (data.fullName) {
		param += '&fullName=' + data.fullName;
	}

	return axios.get(loginUrl + '/ivcs/api/v1/bizrecord/list' + param, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

// 业务记录详情
export const getBizrecordDetail = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizrecord/${id}/detail`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

// 业务记录质检通过
export const updateBizrecordStatus = (id, status) => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/bizrecord/${id}/updateStatus`,
		{ status: status },
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

// 质检状态
export const checkBizrecordStatus = id => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/bizrecord/${id}/check`,
		{},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

// 业务记录历史会话
export const getBizrecordSessions = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizrecord/${id}/sessions`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

// 工作流记录
export const getWorkflowRecord = sessionsId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionsId}/workflow/record`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};
/**
 * 获取业务业务操作记录留痕新接口
 * @param { Number } sessionId 会话 id
 */
export const getBusinessRecord = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/operation/record`);
};
/**
 * 业务场景——进电振铃时长配置
 * @param { Number } bizScenarioId 场景ID  ringingDuration
 */
export const setRingingDuration = (bizScenarioId, ringingDuration) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${bizScenarioId}/ringingDuration`, ringingDuration);
};

/**
 * 判断坐席是否在通话中
 * @param {int} userId 坐席id
 * @returns
 * {
		"code": 200,
		"data": {
			"isServing": false
		},
		"message": "success"
	}
 */
export const isServing = userId => {
	return axios.get(loginUrl + `/ivcs/api/v1/users/${userId}/isServing`);
};
/**
 * 获取用户满意度
 * @param { Number } sessionId 会话 id
 */
export const getServiceRate = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/satisfaction`);
};
// 场景变量相关接口

/**
 * 新增角色
 * @param { Number } scenId 场景ID
 * @param { string } name 角色名
 */
export const addRoleName = (scenId, name) => {
	return axios.post(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/roles`, name);
};

/**
 * 删除角色
 * @param { Number } scenId 场景ID
 * @param { string } name 角色id
 */
export const deldeteRole = (scenId, id) => {
	return axios.delete(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/roles/${id}`);
};
/**
 * 获取全部角色
 * @param { Number } scenId 场景ID
 */
export const getAllRole = scenId => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/roles`);
};
/**
 * 新增客户信息变量
 * @param { Number } scenId 场景ID
 */
export const addCustomerVariables = (scenId, data) => {
	return axios.post(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/variables`, data);
};
/**
 * 获取客户信息详情
 * @param { Number } scenId 场景Id
 * @param { string } variableId 变量Id
 */
export const getCustomerVariablesDetails = (scenId, variableId) => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/variables/${variableId}`);
};
/**
 * 修改客户信息变量
 * @param { Number } scenId 场景Id
 * @param { string } variableId 变量Id
 */
export const updateCustomerVariablesById = (scenId, variableId, data) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/variables/${variableId}`, data);
};
/**
 * 修改客户信息变量
 * @param { Number } scenId 场景Id
 * @param { string } variableId 变量Id
 */
export const deleteCustomerVariablesById = (scenId, variableId, data) => {
	return axios.delete(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/variables/${variableId}`, data);
};
/**
 * 按角色获取客户信息变量
 * @param { Number } scenId 场景Id
 * @param { string } roleId 角色Id
 */
export const getCustomerVariablesByRole = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?roleId=${data.roleId}&page=${data.page}&pageSize=${data.pageSize}`);
};
/**
 * 业务信息变量列表
 * @param { Number } scenId 场景Id
 */
export const getBusinessVariables = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?&page=${data.page}&pageSize=${data.pageSize}`);
};
/**
 *获取会话全部变量及其值，场景变量列表
 * @param { Number } sessionId sessionId
 */
export const getSessionAllVariables = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/variableValues`);
};

/**
 * 按角色获取随路数据的变量
 * @param { Number } scenId 场景Id
 * @param { string } roleId 角色Id
 * @param { string } initMode  初始化方式user-data 随路数据
 */
export const getInitModeVaribles = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?roleId=${data.roleId}&initMode=${data.initMode}`);
};

/**
 * 按角色获取随路数据的变量
 * @param { Number } scenId 场景Id
 * @param { string } initMode  初始化方式user-data 随路数据
 */
export const getBusinessInitModeVaribles = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?initMode=${data.initMode}`);
};

/**
 * 按角色获取客户信息变量
 * @param { Number } scenId 场景Id
 */
export const getVariablesAll = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables/all?page=${data.page}&pageSize=${data.pageSize}&isDisabled=false`);
};

/**
 * 校验角色变量的是否删除
 * @param { Number } scenId 场景ID
 */
export const checkUsedVaribles = data => {
	return axios.post(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables/checkUsed`, data);
};
/**
 * 校验新增客户变量变量名是否存在
 * @param { Number } scenId 场景Id
 */
export const checkVariableName = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?roleId=${data.roleId}&name=${data.name}`);
};
/**
 * 校验新增客户变量初始化字段是否存在
 * @param { Number } scenId 场景Id
 */
export const checkVariableLinkedKey = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?roleId=${data.roleId}&linkedKey=${data.linkedKey}`);
};

/**
 * 校验新增业务变量名是否存在
 * @param { Number } scenId 场景Id
 */
export const checkBuinessVariableName = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?name=${data.name}`);
};
/**
 * 校验新增业务变量初始化字段是否存在
 * @param { Number } scenId 场景Id
 */
export const checkBuinessVariableLinkedKey = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?linkedKey=${data.linkedKey}`);
};

/**
 * 获取会话记录列表
 * @param { data } query参数
 */
export const getSessionRecordList = data => {
	return axios.get(
		loginUrl +
			`/ivcs/api/v1/sessions/list?page=${data.page}&pageSize=${data.pageSize}&startDialingTime=${data.startDialingTime}&endDialingTime=${data.endDialingTime}&isAccepted=${data.isAccepted}&isRinging=${data.isRinging}&isStucked=${data.isStucked}&isNoPicture=${data.isNoPicture}&isGiveUpQueued=${data.isGiveUpQueued}&type=${data.type}&sessionId=${data.sessionId}&userName=${data.userName}&score=${data.score}&summaryIsCompleted=${data.summaryIsCompleted}`
	);
};

/**
 *通话质量详情
 * @param { sessionId } 会话Id sessionId
 */
export const getSessionQuality = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessionStreamQuality?sessionId=${sessionId}`);
};
/**
 *会话统计
  @param { startTime } 开始时间
  @param { endTime } 结束时间
 * @param { type } normal：初始 transfer：转接
 */
export const getSessionStatistics = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/statistics?startTime=${data.startTime}&endTime=${data.endTime}&type=${data.type}`);
};

/**
 * 创建角色
 * @param { String } name 角色名
 * @param { Array } resourceId 权限数组
 */
export const createRole = (name, resourceId) => {
	const data = {
		name: name,
		resourceId: resourceId
	};
	return axios.post(loginUrl + '/ivcs/api/v1/role', data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 修改角色
 * @param { String } name 角色名
 * @param { Array } id 角色ID
 */
export const changeRole = (id, name) => {
	const data = {
		name: name
	};
	return axios.put(loginUrl + `/ivcs/api/v1/role/${id}`, data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 删除角色
 * @param {string} id
 */
export const deleteRole = id => {
	return axios.delete(loginUrl + '/ivcs/api/v1/role/' + id, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 角色列表
 */
export const getRoleList = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/role', {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 修改角色
 * @param { String } resourceId 权限数组
 * @param { Array } id 角色ID
 */
export const changePermission = (id, resourceId) => {
	const data = {
		resourceId: resourceId
	};
	return axios.put(loginUrl + `/ivcs/api/v1/role/${id}/permission`, data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 全部菜单
 */
export const getAllMenu = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/role/allmenu', {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 创建角色
 * @param {*} name 用户名
 * @param {*} pwd  密码
 * @param {*} org  所属机构
 * @param {*} role  角色
 * @param {string} fullName 姓名
 * @param {*} customerLevel  用户等级
 * @param {*} isRobot  是否是机器人坐席
 * @param {*} profile  用户附加信息
 * @param {*} token  当前用户的token
 */
export const createAccount = data => {
	let password = data.pwd;
	if (publicKey) {
		// const sm2 = require('sm-crypto').sm2;
		const cipherMode = 1; // 1 - C1C3C2，0 - C1C2C3，默认为1
		let encryptData = sm2.doEncrypt(password, publicKey, cipherMode); // 加密结果
		password = encryptData;
	}
	data.pwd = password;
	return axios.post(loginUrl + '/ivcs/api/v1/auth/register', data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 修改账号角色
 * @param { String } userId 账号id
 * @param { Array } roleId 角色ID
 */
export const changeAccountRole = (userId, roleId) => {
	const data = {
		userId: userId,
		roleId: roleId
	};
	return axios.put(loginUrl + '/ivcs/api/v1/users/role', data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 用户登出
 */
export const logout = () => {
	return axios.post(
		loginUrl + '/ivcs/api/v1/auth/logout',
		{},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};
/**
 * 获取机构下所有分组
 * @param {string} org
 * @returns
 */
export const getGroupsListWithOrg = org => {
	return axios.get(loginUrl + `/ivcs/api/v1/groups/org/${org}`);
};

/**
 * 批量导入分组
 * @param {List<string>} groups 分组名列表
 * @returns
 */
export const importGroups = groups => {
	let groupList = groups.map(value => {
		return { name: value };
	});
	return postWithToken(loginUrl + `/ivcs/api/v1/groups/import`, { groups: groupList });
};

/**
 * 坐席状态日志列表
 * @param {object} data {group:string,status:string,userName:string,startTime:string,endTime:string,page:number,pageSize:number}
 * @returns
 */
export const getAgentStatsuLogList = data => {
	return axios.get(
		loginUrl +
			`/ivcs/api/v1/agentStatusLog/list?groupId=${data.groupId}&status=${data.status}&userName=${data.userName}&startTime=${data.startTime}&endTime=${data.endTime}&page=${data.page}&pageSize=${data.pageSize}`
	);
};

/**
 * 运管操作日志列表
 * @param {object} data {type:string,userName:string,startTime:string,endTime:string,page:number,pageSize:number}
 * @returns
 */
export const getOperationLogList = data => {
	return axios.get(
		loginUrl + `/ivcs/api/v1/operationLog/list?type=${data.type}&userName=${data.userName}&startTime=${data.startTime}&endTime=${data.endTime}&page=${data.page}&pageSize=${data.pageSize}`
	);
};

/**
 * 创建操作日志
 * @param {*} data {type:类型 0：登入登出 1:运营管理,category:分类 downloadAndExport：下载&导出，logInOrOut：登入/登出,content:内容}
 * @returns
 */
export const setOperationLog = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/operationLog', data);
};

/**
 * 业务场景配置项, 启用/停用 实时质检
 * @param { Number } scenId 场景ID
 * @param { Boolean } isRealTimeQualityOn  = true || false
 */
export const setIsRealTimeQualityOn = (scenId, isRealTimeQualityOn) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/isRealTimeQualityOn`, isRealTimeQualityOn);
};
/**
 * 新建实时质检配置
 * @param { Number } scenId 场景ID
 * @param { Object } data
 */
export const addQualityes = (scenId, data) => {
	return axios.post(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/quality`, data);
};
/**
 * 更新实时质检配置
 * @param { Number } scenId 场景Id
 * @param { string } id 场景质检项id
 */
export const updateQualityesById = (scenId, id, data) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/quality/${id}`, data);
};
/**
 * 删除实时质检配置
 * @param { Number } scenId 场景Id
 * @param { string } id 场景质检项id
 */
export const deleteQualityesById = (scenId, id, data) => {
	return axios.delete(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/quality/${id}`, data);
};
/**
 * 获取全部实时质检配置列表
 * @param { Number } scenId 场景ID
 */
export const getAllQualityesList = scenId => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/quality`);
};
/**
 *获取单项实时质检配置
 * @param { Number } scenId 场景ID
 * @param { string } id 场景质检项id
 */
export const getSingleQualityes = (scenId, id) => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/quality/${id}`);
};
/**
 *获取实时质检报告列表
 * @param { string } sessionId
 */
export const getBizflowquality = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/bizflowquality/report`);
};
/**
 *获取单项实时质检配置
 * @param { string } sessionId
 * @param { string } category  质检分类， 1：人脸对比，2：活体检测:3：客户敏感词:4：坐席敏感词
 */
export const getCategoryQuality = (sessionId, category, isPass) => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/bizflowquality/record?category=${category}&isPass=${isPass}`);
};
/**
 * 若关闭人脸比对时检测到实时质检中配置了该质检项并为开启状态则taost提示“实时质检添加了人脸比对项，无法关闭！
 * @param { Number } scenId 场景ID
 * @param { string } category  质检分类，  1：人脸对比，2：活体检测:3：客户敏感词:4：坐席敏感词
 */
export const validateByCategory = (scenId, category) => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/quality?category=${category}`);
};

/**
 * 校验账号是否有工作台权限
 * @param { string } userId  账号id
 */
export const checkWorkbench = userId => {
	return axios.get(loginUrl + `/ivcs/api/v1/auth/users/${userId}/checkWorkbench`);
};

/**
 * 修改账号的 fullName （真实姓名）
 * @param { string } userId  账号id
 * @param { string } fullName  账号姓名
 */
export const modifyUserFullName = (userId, fullName) => {
	return putWithToken(loginUrl + `/ivcs/api/v1/auth/users/${userId}/fullName`, { fullName });
};

/**
 * 批量导入账号
 *
 * @typedef {Object} AccountData
 * @property {string} userName - 用户名
 * @property {string | number} roleId 角色 id
 * @property {string} fullName 真实姓名
 * @property {string} pwd 密码
 * @property {Array<string | number>} groupIds 分组 id 列表
 * @property {Array<string | number>} labelIds  标签 id 列表
 * @property {"N" | "Y"} isDisabled 是否开启 'N': 开启  'Y': 停用
 * @description {@link AccountData}
 * @param { Array<AccountData>} accounts 账号列表
 */
export const importAccounts = accounts => {
	console.log('importAccounts', accounts);
	return postWithToken(loginUrl + `/ivcs/api/v1/auth/users/import`, { users: accounts });
};

// 黑名单管理相关接口
/**
 *获取黑名单用户列表
 * @param { Object }  data
 */
export const getBanUserList = data => {
	return axios.get(
		loginUrl + `/ivcs/api/v1/banUser?page=${data.page}&pageSize=${data.pageSize}&title=${data.title}&userId=${data.userId}&createdAtStart=${data.createdAtStart}&createdAtEnd=${data.createdAtEnd}`
	);
};
/**
 *新增黑名单用户
 * @param { Object }  data
 */
export const addBanUser = data => {
	return axios.post(loginUrl + `/ivcs/api/v1/banUser`, data);
};
/**
 *修改黑名单用户
 * @param { Object }  data
 * @param { Number }  id  用户id
 */
export const updateBanUser = (id, data) => {
	return axios.put(loginUrl + `/ivcs/api/v1/banUser/${id}`, data);
};
/**
 *删除黑名单用户
 * @param { Object }  data
 * @param { Number }  id  用户id
 */
export const delBanUser = id => {
	return axios.delete(loginUrl + `/ivcs/api/v1/banUser/${id}`);
};
/**
 *获取黑名单分组列表列表
 * @param { Object }  data
 */
export const getBanGroupList = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/banGroup?page=${data.page}&pageSize=${data.pageSize}&title=${data.title}&createdAtStart=${data.createdAtStart}&createdAtEnd=${data.createdAtEnd}`);
};
/**
 * 获取黑名单分组选项列表
 * @param {  }
 */
export const getBanGroupOptions = () => {
	return axios.get(loginUrl + `/ivcs/api/v1/banGroup/options`);
};
/**
 *新增黑名单分组
 * @param { Object }  data
 */
export const addBanGroup = data => {
	return axios.post(loginUrl + `/ivcs/api/v1/banGroup`, data);
};
/**
 *修改黑名单分组
 * @param { Object }  data
 * @param { Number }  id  分组id
 */
export const updateBanGroup = (id, data) => {
	return axios.put(loginUrl + `/ivcs/api/v1/banGroup/${id}`, data);
};
/**
 *删除黑名单分组
 * @param { Object }  data
 * @param { Number }  id  分组id
 */
export const delBanGroup = id => {
	return axios.delete(loginUrl + `/ivcs/api/v1/banGroup/${id}`);
};
/**
 * 获取黑名单呼叫记录列表
 * @param { Object }  data
 */
export const getBanUserSession = data => {
	return axios.get(
		loginUrl +
			`/ivcs/api/v1/banUser/session?page=${data.page}&pageSize=${data.pageSize}&sceneName=${data.sceneName}&userId=${data.userId}&banGroupName=${data.banGroupName}&createdAtStart=${data.createdAtStart}&createdAtEnd=${data.createdAtEnd}&sessionId=${data.sessionId}`
	);
};
/**
 *校验黑名单分组是否绑定用户
 * @param { Number }  id  用户id
 */
export const checkBandGroup = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/banGroup/${id}/used`);
};
/**
 * 获取客户信息已启用的默认变量
 * @param { Number } scenId 场景Id
 * @param { string } roleId 角色Id
 * @param { Boolean } isDisabled  默认变量停启用 true 停用 ||  false 启用
 */
export const getVariablesByDisabled = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?roleId=${data.roleId}&page=${data.page}&pageSize=${data.pageSize}&isDisabled=${data.isDisabled}`);
};
/**
 * 添加变量，信息汇总 必须是随路数据已启用的变量
 * @param { Number } scenId 场景Id
 * @param { string } roleId 角色Id
 * @param { string } initMode  初始化方式user-data 随路数据
 * @param { Boolean } isDisabled  默认变量停启用 true 停用 ||  false 启用
 */
export const getInitModeAddSummaryVaribles = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${data.scenId}/variables?roleId=${data.roleId}&initMode=${data.initMode}&isDisabled=false`);
};

/**
 * 获取登录地址
 * @param { string } redirect_uri
 * @param { string } org 机构
 */
export const getLoginUrl = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/oauth/loginUrl?redirect_uri=${data.redirect_uri}&org=${data.org}`);
};
/**
 * code登录
 * @param { string } code
 * @param { string } state
 */
export const accountLogin = data => {
	return axios.post(loginUrl + `/ivcs/api/v1/oauth/callback`, data);
};
/**
 * 创建业务标签
 * @param String name 标签名称
 * @returns
 */
export const createBizLabel = name => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/bizlabel`,
		{ name: name },
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`),
				'Content-Type': 'application/json'
			}
		}
	);
};

/**
 * 获取业务标签列表
 * @param {{ page: number, pageSize: number }} data 分页信息
 * @returns
 */
export const getBizLabelList = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizlabel?page=${data.page}&pageSize=${data.pageSize}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`),
			'Content-Type': 'application/json'
		}
	});
};
/**
 * 根据标签 id 删除标签
 * @param { number | string} labelId 标签 id
 * @returns
 */
export const deleteBizLabelById = labelId => {
	return axios.delete(loginUrl + `/ivcs/api/v1/bizlabel/${labelId}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`),
			'Content-Type': 'application/json'
		}
	});
};
/**
 * 根据标签 id 修改标签
 * @param { number | string} labelId 标签 id
 * @param {{ name: string }} labelData 新的标签数据
 * @returns
 */
export const modifyBizLabelById = (labelId, labelData) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizlabel/${labelId}`, labelData, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`),
			'Content-Type': 'application/json'
		}
	});
};
/**
 * 为用户绑定标签
 * @param { number | string} userId 用户 id
 * @param { Array<number | string> } labelabelIds 标签 id 列表
 * @returns
 */
export const bindBizLabelsToUser = (userId, labelabelIds) => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/users/${userId}/labels`,
		{ labelIds: labelabelIds },
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`),
				'Content-Type': 'application/json'
			}
		}
	);
};
/**
 * 获取用户绑定的标签
 * @param { number | string} userId 用户 id
 * @param {{ page: number, pageSize: number}} pages 分页
 * @returns
 */
export const getUserBizLabels = (userId, pages) => {
	return axios.get(loginUrl + `/ivcs/api/v1/users/${userId}/labels?page=${pages.page}&pageSize=${pages.pageSize}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`),
			'Content-Type': 'application/json'
		}
	});
};

/**
 * 添加 业务资料
 * @param { Number | String } sceneId 业务场景 id
 * @param { { title: String, content: String, fileSize: Number, fileName: String, type: 'video' | 'document'} }  title 文档资料标题
 * @param content 文档资料链接
 * @param fileSize
 * @param fileName
 * @param type 'video' | 'document'
 * @returns
 */
export const addBusinessResource = (sceneId, { title, content, fileSize, fileName, type }) => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/bizscenarios/${sceneId}/material`,
		{ title, content, fileSize, fileName, type },
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 删除 业务资料
 * @param { Number | String } sceneId 业务场景 id
 * @param { Number | String } resourceId 业务资料 id
 * @returns
 */
export const deleteBusinessResource = (sceneId, resourceId) => {
	return axios.delete(loginUrl + `/ivcs/api/v1/bizscenarios/${sceneId}/material/${resourceId}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取业务资料列表
 * @param { Number | String } sceneId 业务场景 id
 * @param { 'video' | 'document' } type 业务资料类型 'video' | 'document'
 * @param { { page: Number | String, pageSize: Number | String } }  page
 * @param pageSize
 * @returns
 */
export const getBusinessResourcesBySceneId = (sceneId, type, { page, pageSize }) => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${sceneId}/material?page=${page}&pageSize=${pageSize}&type=${type}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 新增知识库
 * @param {*} data {name:问题,answer:答案,type:'', fileName: '', categoryId:0}
 * @returns
 */
export const createKnowledgeBase = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/knowledge', data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取知识库列表
 * @param {*} data {page:1,pageSize:10,name:'',categoryId:0}
 * @returns
 */
export const getKnowledgeBaseList = data => {
	const { page, pageSize, categoryId, name } = data;
	let url = loginUrl + `/ivcs/api/v1/knowledge?page=${page}&pageSize=${pageSize}`;
	if (name) {
		url += `&name=${name}`;
	} else {
		url += `&categoryId=${categoryId}`;
	}
	return axios.get(url, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 删除知识库
 * @param {*} id
 * @returns
 */
export const deleteKnowledgeBase = id => {
	return axios.delete(loginUrl + `/ivcs/api/v1/knowledge/${id}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 新增知识库分类
 * @param {*} data {name:分类名称, parentId:0}
 * @returns
 */
export const createKnowledgeBaseCategory = data => {
	return axios.post(loginUrl + '/ivcs/api/v1/knowledge/category', data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 删除知识库分类
 * @param {*} id
 * @returns
 */
export const deleteKnowledgeBaseCategory = id => {
	return axios.delete(loginUrl + `/ivcs/api/v1/knowledge/category/${id}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 知识库分类列表
 * @param {*} data {page:1,pageSize:10}
 * @returns
 */
export const getKnowledgeBaseCategoryList = data => {
	return axios.get(loginUrl + `/ivcs/api/v1/knowledge/category?page=${data.page}&pageSize=${data.pageSize}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 知识库分类列表(不分页)
 * @returns
 */
export const getKnowledgeBaseCategoryAll = () => {
	return axios.get(loginUrl + '/ivcs/api/v1/knowledge/category', {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 知识库评价列表
 * @param {*} id
 * @returns
 */
export const getKnowledgeBaseFeedbackList = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/knowledge/${id}/feedback`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 修改知识库
 * @param {*} data {id: '', name: '', answer: '', categoryId: 0, type: '', fileName: ''}
 * @returns
 */
export const updateKnowledgeBase = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/knowledge/${data.id}`, data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 修改知识库分类
 * @param {*} id
 * @param {*} name
 * @returns
 */
export const updateKnowledgeBaseCategory = (id, name) => {
	const data = {
		name
	};
	return axios.put(loginUrl + `/ivcs/api/v1/knowledge/category/${id}`, data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 知识库查询
 * @param {*} question
 * @returns
 */
export const getKnowledgeBaseByQuestion = question => {
	return axios.get(loginUrl + `/ivcs/api/v1/knowledge/ask?question=${question}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取知识库分类的父分类
 * @param {*} id
 * @returns
 */
export const getKnowledgeBaseCategoryParent = id => {
	return axios.get(loginUrl + `/ivcs/api/v1/knowledge/category/${id}/parent`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 批量修改知识库的分类
 * @param {*} data {"categoryId":22,"knowledgeIds": [14,15,16,17]}
 * @returns
 */
export const batchUpdateKnowledgeBaseCategory = data => {
	return axios.put(loginUrl + `/ivcs/api/v1/knowledge/batch/category`, data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 批量删除知识库
 * @param {*} data "ids":[9,10]
 * @returns
 */
export const batchDeleteKnowledgeBase = data => {
	return axios.delete(loginUrl + `/ivcs/api/v1/knowledge`, {
		data,
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 批量导入知识库
 * @param {*} data [{"categoryId": 22,"name": "知识库名称111sd111sddsdsd11ssssss1", "answer": "知识库答案", "type": "text", "fileName": null}]
 * @returns
 */
export const importKnowledgeBase = data => {
	return axios.post(loginUrl + `/ivcs/api/v1/knowledge/import`, data, {
		headers: {
			'Content-Type': 'application/json',
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 新增会话小结配置项
 * @param {*} scenId
 * @param {*} data {"name": "字段名称","type": "single-line-text","data": {},"isRequired": "Y"}
 * @param {string} name 字段名称
 * @param {string} type 字段类型 single-line-text”, “single-selection”, “multiple-selection”, “radio”, “multiple-line-text”
 * @param {object} data 字段数据
 * @param {string} isRequired 是否必填 Y N
 * @returns
 */
export const addSessionSummary = (scenId, data) => {
	return axios.post(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/summary`, data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 更新会话小结配置项
 * @param {*} scenId
 * @param {*} id
 * @param {*} data {"name": "字段名称","type": "single-line-text","data": {},"isRequired": "Y"}
 * @returns
 */
export const updateSessionSummary = (scenId, id, data) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/summary/${id}`, data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取会话小结配置项列表
 * @param {*} scenId
 * @returns
 */
export const getSessionSummaryList = scenId => {
	return axios.get(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/summary`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 删除会话小结配置项
 * @param {*} scenId
 * @param {*} id
 * @returns
 */
export const deleteSessionSummary = (scenId, id) => {
	return axios.delete(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/summary/${id}`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 开启/停用会话小结
 * @param {*} scenId
 * @param {*} data { enable: 'Y' | 'N' }
 * @returns
 */
export const setSessionSummaryStatus = (scenId, data) => {
	return axios.put(loginUrl + `/ivcs/api/v1/bizscenarios/${scenId}/isSummaryOn`, data, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 获取当前通话的会话小结
 * @param {string} sessionId 会话id
 * @returns
 */
export const getBizSessionSummary = sessionId => {
	return axios.get(loginUrl + `/ivcs/api/v1/sessions/${sessionId}/bizSummary`, {
		headers: {
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

/**
 * 服务记录导出
 * @param params
 * @returns
 */
export const exportSessionList = data => {
	return axios.get(
		loginUrl +
			`/ivcs/api/v1/sessions/list/export?startDialingTime=${data.startDialingTime}&endDialingTime=${data.endDialingTime}&isAccepted=${data.isAccepted}&isRinging=${data.isRinging}&isStucked=${data.isStucked}&isNoPicture=${data.isNoPicture}&isGiveUpQueued=${data.isGiveUpQueued}&type=${data.type}&sessionId=${data.sessionId}&userName=${data.userName}&score=${data.score}&summaryIsCompleted=${data.summaryIsCompleted}`,
		{
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			},
			responseType: 'arraybuffer'
		}
	);
};

/**
 * 解锁账号
 * @param {string} userId
 */
export const unlock = userId => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/auth/users/${userId}/unlock`,
		{},
		{
			headers: {
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			}
		}
	);
};

/**
 * 超级管理员解锁管理员帐号
 * @param {*} userId
 * @returns
 */
export const superUnlockAccount = userId => {
	return axios.post(
		loginUrl + `/ivcs/api/v1/auth/users/${userId}/unlock`,
		{},
		{
			headers: {
				'x-access-token': localStorage.getItem('superAdminToken')
			}
		}
	);
};

/**
 * 导入ai工作流
 * @param {string} id 业务流程id
 * @param {object} data json文件内容
 * @returns
 */
export const importAiBusinessflow = (id, data) => {
	return axios.post(loginUrl + `/ivcs/api/v1/businessflow/${id}/Import`, data, {
		headers: {
			'Content-Type': 'application/json',
			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
		}
	});
};

// /**
//  * 导出ai工作流
//  * @param {string} id 业务流程id
//  * @returns
//  */
// export const exportAiBusinessflow = id => {
// 	return axios.get(loginUrl + `/ivcs/api/v1/businessflow/${id}/export`, {
// 		headers: {
// 			'Content-Type': 'application/json',
// 			'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
// 		},
// 		responseType: 'json'
// 	});
// };

/**
 * 导出ai工作流
 * @param {string} id 业务流程id
 * @returns
 */
export const exportAiBusinessflow = id => {
	return axios
		.get(loginUrl + `/ivcs/api/v1/businessflow/${id}/export`, {
			headers: {
				'Content-Type': 'application/json',
				'x-access-token': localStorage.getItem(`zco_admin_token_${window.uid}`)
			},
			responseType: 'blob' // 设置为 blob 以便处理文件流
		})
		.then(response => {
			// 创建一个 URL 对象
			const url = window.URL.createObjectURL(new Blob([response.data]));
			// 创建一个 <a> 元素
			const link = document.createElement('a');
			link.href = url;
			link.setAttribute('download', `businessflow_${id}.json`); // 设置下载的文件名
			document.body.appendChild(link);
			link.click();
			// 清理
			document.body.removeChild(link);
			window.URL.revokeObjectURL(url);
		})
		.catch(error => {
			console.error('下载失败:', error);
		});
};
